{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "787e61ad",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "## 1.字符串\n",
    "## 2.列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd036b46",
   "metadata": {},
   "source": [
    "## 1.字符串\n",
    "* 关于字符的基本内容\n",
    "* 关于字符串的方法及函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b51b5a6f",
   "metadata": {},
   "source": [
    "## 1.1关于字符串的基本内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4f76ee4e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'spam eggs'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'spam eggs'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "734bc316",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(type(\"spam eggs\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f0b067b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(type(\"spam eggs\" ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ca26f48a",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (3578565646.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [7]\u001b[1;36m\u001b[0m\n\u001b[1;33m    'doesn't'\u001b[0m\n\u001b[1;37m           ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "'doesn't'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "bfe45bc9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 以上解决方案\n",
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "319dff2c",
   "metadata": {},
   "source": [
    " # 三引号：保留字符串信息的 格式信息的，保留完整的数据信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "7be33b8e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''doesn't'''"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "734a9b30",
   "metadata": {},
   "source": [
    "# 1.2关于字符串的方法及函数\n",
    ">1. 字符串是可以拼接的（字符串的运算）,用 + 进行字符串之间的拼接\n",
    ">2. 字符串是有顺序的,从第一个字符开始，从0依次往后；有长度，可以用len()检查字符串的长度\n",
    ">3. 字符串的取值：\n",
    ">>1. 取单个值 :从左往右（正数，第一个值是0），从右往左（负数，第一个值是-1）\n",
    ">>2. 取多个值 :切片的方法，两个值作为 取值的区间\n",
    ">4. 字符串的方法及函数\n",
    ">>1. in 查询成员是否存在\n",
    ">>2. str.count() 查询数量\n",
    ">>3. str.isdigit() 判断字符串是否是 数字\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6cdc93c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_name = [\"小明\",\"小红\",\"张杰\",\"李华\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "9d8bced2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院团委欢迎小明\n",
      "广州南方学院团委欢迎小红\n",
      "广州南方学院团委欢迎张杰\n",
      "广州南方学院团委欢迎李华\n"
     ]
    }
   ],
   "source": [
    "for i in new_name:\n",
    "    print(\"广州南方学院团委欢迎\"+i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "72136a40",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委欢迎小明'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州南方学院团委欢迎\"+\"小明\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "9244b270",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委欢迎小明'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = '广州南方学院团委欢迎小明'\n",
    "text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "6f1aa07b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "0e7cb542",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'南'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "6ad5403a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'委'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "10717cec",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "string index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [22]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mtext\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m12\u001b[39;49m\u001b[43m]\u001b[49m\n",
      "\u001b[1;31mIndexError\u001b[0m: string index out of range"
     ]
    }
   ],
   "source": [
    " text[12]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "764123f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "d8ae574a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[6]+text[7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "7273ef65",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[6:8]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e21c30f4",
   "metadata": {},
   "source": [
    "## in 查询成员"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "801c10f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'广州' in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "5679ae11",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'北京' in text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "06ba70f0",
   "metadata": {},
   "source": [
    "## str.count()查询数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "039cefb1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text.count('广州')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "73a9c024",
   "metadata": {},
   "source": [
    "## str.count()判断字符串是否是数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "c8e3f16f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "age_li = 19\n",
    "age_wang = '19'\n",
    "print(age_li,type(age_li))\n",
    "print(age_wang,type(age_wang))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "8ca425f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_wang.isdigit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "0f529891",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text.isdigit()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99392ff2",
   "metadata": {},
   "source": [
    "# 2.有序的数据结构——列表list\n",
    ">1. 列表的基本运算法则（参考：有序的数据结构的运算法则列表）\n",
    ">2. 列表的一般方法（要求：全部掌握，并且做总结在课后笔记中）\n",
    "### 2.1 列表的基本运算法则"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "954d9a55",
   "metadata": {},
   "outputs": [],
   "source": [
    "网二_name = \"李华，小明，李晓华，小红\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "0c2bdea7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(网二_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "a286af7a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李华'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "e809c6bb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小明'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name[3:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7182556c",
   "metadata": {},
   "source": [
    "### 对比字符串和列表\n",
    ">1. 字符串是按照字符进行数据取值\n",
    ">2. 列表是按照元素进行数据取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "21d59cad",
   "metadata": {},
   "outputs": [],
   "source": [
    "网二_name_list = [\"李华\",\"小明\",\"李晓华\",\"小红\"] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "0f4bafa3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(网二_name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "68af6223",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李华'"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "0e7b9724",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['李晓华', '小红']"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name_list[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "142a692b",
   "metadata": {},
   "outputs": [],
   "source": [
    "网二_age_list = [19,18,19,20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "aeb0bd3e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_age_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "0dad0a05",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[19, 18, 19, 20]"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_age_list[:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "4ccc3233",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_age_list.count(19)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb043fb2",
   "metadata": {},
   "source": [
    "### 2.2列表的方法\n",
    ">1.增加\n",
    ">2.删除\n",
    ">3.修改\n",
    ">4.查询 in，count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "044e8ba6",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "80d80185",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
